set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ")

add_compile_options(-fPIC)

include_directories(${PROJECT_SOURCE_DIR}/include)

set (SRCS
    acceptor.cpp
    address.cpp
    connection.cpp
    notifier.cpp
    ioloop.cpp
    poller.cpp
    process.cpp
    signaler.cpp
    sockutil.cpp
    snowutil.cpp
    stringutil.cpp
    tcpserver.cpp
    tcpclient.cpp
    timer.cpp
    timingwheel.cpp
    tnet.cpp
    polarssl/base64.cpp
	polarssl/md5.cpp
	polarssl/sha1.cpp
    inotifyer.cpp
    logutil.cpp
    servconf.cpp
    udputil.cpp
    smtpclient.cpp
    ftpclient.cpp
    )


if(ENABLE_USE_LOGCPLUS) 
message(STATUS "USE_LOGCPLUS " ${ENABLE_USE_LOGCPLUS})
include_directories($ENV{HOME}/include)
add_definitions(-DENABLE_USE_LOGCPLUS)
set (LOG_SRCS 
    $ENV{HOME}/logcplus/include/pugixml/pugixml.hpp
    $ENV{HOME}/logcplus/include/pugixml/pugixml.cpp
    $ENV{HOME}/logcplus/src/logcplus_lockutil.cpp
    $ENV{HOME}/logcplus/src/logcplus_fileutil.cpp
    $ENV{HOME}/logcplus/src/logcplus_string.cpp
    $ENV{HOME}/logcplus/src/logcplus_util.cpp
    $ENV{HOME}/logcplus/src/logcplus_common.cpp
    $ENV{HOME}/logcplus/src/logcplus_layout.cpp
    $ENV{HOME}/logcplus/src/logcplus_properties.cpp
    $ENV{HOME}/logcplus/src/logcplus_buffer.cpp   
    $ENV{HOME}/logcplus/src/logcplus_debug_util.cpp
    $ENV{HOME}/logcplus/src/logcplus_log_clean.cpp
    $ENV{HOME}/logcplus/src/logcplus_lock.cpp
    $ENV{HOME}/logcplus/src/logcplus_base_writer.cpp 
    $ENV{HOME}/logcplus/src/logcplus_writer_file.cpp
	)
endif() 

if(ENABLE_USE_OPENSSL)
message(STATUS "USE_SSL " ${ENABLE_USE_OPENSSL})
add_definitions(-DENABLE_USE_OPENSSL)
set (SSL_SRCS ssl_wrap.cpp)
endif()

add_library(toptnet ${SRCS} ${LOG_SRCS} ${SSL_SRCS})
target_link_libraries(toptnet rt )

if(ENABLE_USE_OPENSSL)
target_link_libraries(toptnet ssl crypto)
endif()

if(NOT LIBRARY_INSTALL_PATH)
	set(LIBRARY_INSTALL_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL
		   "Single install directory for building all libraries.")
endif()

if(NOT INCLUDE_INSTALL_PATH)
	set(INCLUDE_INSTALL_PATH ${CMAKE_BINARY_DIR}/include CACHE INTERNAL
		   "Single install directory for building all includes.")
endif() 
##set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

install(TARGETS toptnet DESTINATION ${LIBRARY_INSTALL_PATH})

set (HEADERS
    address.h
    connection.h
    connector.h
    connector.inl
    nocopyable.h
    notifier.h
    signaler.h
    sockutil.h
    spinlock.h
    stringutil.h
    tcpserver.h
    tcpclient.h
    timer.h
    timingwheel.h
    tnet.h 
    inotifyer.h
    snowutil.h
    ioloop.h
    logutil.h
    servconf.h
    udputil.h
    smtpclient.h
    ftpclient.h
    tcpconnection.h
    tcpservice.h
    )

install(FILES ${HEADERS} DESTINATION ${INCLUDE_INSTALL_PATH}/tnet)

add_subdirectory(http)
add_subdirectory(redis)